package org.dgt.model.core;

import java.util.Date;
import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.Transaction;

public class Main {
	public static void main(String[] args) {
		Session session = HibernateUtil.getSessionFactory().openSession();
		Transaction transaction = null;
		try {
			transaction = session.beginTransaction();
			//create user
			UserInformation user = new UserInformation();
			user.setName("Tin Nguyen");
			user.setDob(new Date());
			user.setEmail("kyotin@yahoo.com");
			user.setPhone("0906345360");
			session.save(user);
			
			//create product;
			Product product = new Product();
			product.setName("May Tinh");
			List<UserInformation> usrs = session.createCriteria(UserInformation.class).list();
			
			session.save(product);
			
			transaction.commit();
		} catch (HibernateException e) {
			transaction.rollback();
			e.printStackTrace();
		} finally {
			session.close();
		}
		
	}
}
